<template>
  <div class="container">
    <div class="box">
      <div class="login">欢迎登陆智慧校园系统</div>
      <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
        <el-form-item label="" prop="username">
          <el-input v-model="ruleForm.username" autocomplete="off" placeholder="用户名称" clearable></el-input>
        </el-form-item>
        <el-form-item label="" prop="password">
          <el-input type="password" v-model="ruleForm.password" autocomplete="off" placeholder="用户密码" clearable></el-input>
        </el-form-item>
        <el-form-item>
          <div style="margin-bottom: 15px">
            <el-button type="primary" @click="submitForm('ruleForm')" class="login-btn">立即登录</el-button>
          </div>
<!--          <div>-->
<!--            <el-button @click="resetForm('ruleForm')" class="reset-btn">重置</el-button>-->
<!--          </div>-->
          <router-link tag="span" :to="{path:'register'}">
            <el-button class="register-btn">注册</el-button>
          </router-link>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
import { AddRoutes } from "@/router";

export default {
  data() {
    return {
      ruleForm: {
        username: "",
        password: ""
      },
      rules: {
        username: [
          { required: true, message: '请输入用户名称', trigger: 'blur' },
        ],
        password: [
          { required: true, message: '请输入密码', trigger: 'blur' },
        ],
      }
    };
  },
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          console.log(this.ruleForm)
          this.$axios.post("/sysUser/login", this.ruleForm).then(res => {
            console.log(res)
            if (res.code === 200) {
              this.$message({
                message: "登录成功，正在跳转",
                type: "success"
              })
              let userInfo = res.data
              localStorage.setItem("systemUser", JSON.stringify(userInfo))
              localStorage.setItem("systemRoleMenu", JSON.stringify(userInfo.roleMenu))
              AddRoutes()
              if (res.data.roleType === "USER") {
                this.$router.push({ path: "/front" })
              } else {
                this.$router.push({ path: "/" })
              }
            }
          })
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    }
  }
}
</script>
<style>
.box .el-form-item__content {
  margin-left: 0 !important;
}

.box .el-button {
  width: 100% !important;
}

</style>
<style scoped>
.login-btn {
  background: linear-gradient(135deg, #6a11cb, #2575fc);
  border: none;
  color: white;
  font-size: 16px;
  border-radius: 25px;
  padding: 10px 20px;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.login-btn:hover {
  transform: scale(1.05);
  box-shadow: 0 6px 8px rgba(0, 0, 0, 0.15);
}
.register-btn {
  background: linear-gradient(135deg, #4facfe, #00f2fe);
  border: none;
  color: white;
  font-size: 16px;
  border-radius: 25px;
  padding: 10px 20px;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.register-btn:hover {
  transform: scale(1.05);
  box-shadow: 0 6px 8px rgba(0, 0, 0, 0.15);

}
.container {
  width: 100%;
  height: 100vh;
  position: relative;
  background: url("../assets/a.jpg") 100% 100% ;
  display: flex;
  justify-content: center;
  align-items: center;
}

.login {
  text-align: center;
  margin-bottom: 25px;
  font-size: 28px;
  color: #2575fc;
  font-weight: bold;
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.2);
}

.box {
  overflow: hidden;
  width: 400px;
  padding: 30px;
  box-sizing: border-box;
  background: rgba(0, 0, 100, 0.5);  /* 半透明的白色背景 */
  border-radius: 15px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
  animation: fadeIn 0.5s ease-in-out;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(-20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
</style>